import React from 'react'
import styles from './index.module.scss'
import { useEffect, useRef } from 'react'
import classNames from 'classnames'
export default function Input({
  extra,
  onExtra,
  className,
  autofocus,
  ...rest
}) {
  const InputRef = useRef(null)
  useEffect(() => {
    if (autofocus) {
      InputRef.current.focus()
    }
  }, [autofocus])
  return (
    <div className={classNames(styles.root, className)}>
      <input ref={InputRef} type="text" className="input" {...rest} />
      {extra && (
        <div className="extra" onClick={onExtra}>
          {extra}
        </div>
      )}
    </div>
  )
}
